import time
from concurrent.futures import ProcessPoolExecutor


def task(name: str):
    print(f"{name} step 1\n", end="")
    time.sleep(0.1)
    print(f"{name} step 2\n", end="")
    return f"{name} complete"


if __name__ == '__main__':
    with ProcessPoolExecutor() as executor:
        result1 = executor.submit(task, "A")
        result2 = executor.submit(task, "B")

        # 这里的result() 会等待线程执行完毕 再执行
        print(result1.result())
        print(result2.result())

    with ProcessPoolExecutor() as executor:
        results = executor.map(task, ["C", "D"])

        for r in results:
            print(r)  # 获取线程的返回值
